"""Route model."""
from app import db
from app.models.base import BaseModel


class Route(BaseModel):
    """Route model representing walking paths."""
    
    __tablename__ = 'routes'
    
    start_latitude = db.Column(db.Float, nullable=False)
    start_longitude = db.Column(db.Float, nullable=False)
    end_latitude = db.Column(db.Float, nullable=False)
    end_longitude = db.Column(db.Float, nullable=False)
    waypoints = db.Column(db.JSON, default=list)
    distance_meters = db.Column(db.Float)
    estimated_duration = db.Column(db.Integer)  # minutes
    target_poi_id = db.Column(db.String(36), db.ForeignKey('pois.id'))
    
    # Relationship
    target_poi = db.relationship('POI')
    
    def to_dict(self):
        """Convert route to dictionary."""
        return {
            'id': self.id,
            'start_location': {
                'latitude': self.start_latitude,
                'longitude': self.start_longitude
            },
            'end_location': {
                'latitude': self.end_latitude,
                'longitude': self.end_longitude
            },
            'waypoints': self.waypoints,
            'distance_meters': self.distance_meters,
            'estimated_duration': self.estimated_duration,
            'target_poi_id': self.target_poi_id,
            'created_at': self.created_at.isoformat() if self.created_at else None
        }
